package gui;

import dataconnect.Investment;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.table.DefaultTableModel;
import java.awt.BorderLayout;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/**
 * description: Query
 * 查询页面
 * @author what-is-me
 * @date 2022/1/3 23:39
 */
public class Query extends JPanel {
    public static DefaultTableModel tModel = new DefaultTableModel();
    String type;

    public Query(String ty) {
        /**
         * Description: Query
         * @param ty:java.lang.String
         * @return {@link null}
         * @throws
         * @author what-is-me
         * @date 2022/1/3 23:39
         */
        super(new BorderLayout());
        this.type = ty;
        GridBagPanel search = new GridBagPanel(), res = new GridBagPanel();
        JLabel t = new JLabel((ty.equals("byyear") ? "按年份" : "按名字") + "搜索:");
        t.setFont(new Font("宋体", Font.PLAIN, 20));
        search.add(t, 0, 0, 1, 1);
        JTextField input = new JTextField(30);
        search.add(input, 1, 0, 3, 1, 0, 10);
        JButton b = new JButton("查询");
        b.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                Message.msg = type;
                Message.args[0] = input.getText();
            }
        });
        search.add(b, 5, 0, 1, 2, 0, 10);
        add(search, BorderLayout.NORTH);
        JTable table = new JTable(tModel);
        table.setFont(new Font("宋体", Font.PLAIN, 16));
        table.setRowHeight(20);
        table.getTableHeader().setFont(new Font("宋体", Font.PLAIN, 16));
        JScrollPane scrollPane = new JScrollPane(table);
        res.add(scrollPane, 0, 0, 1, 1, 1, 0);
        add(res, BorderLayout.CENTER);
        tModel.setDataVector(null, Investment.tag);
    }
}